ProductListView = new function() {
    this.OnLoad = _onLoad;
    
    function _onLoad(){
        $('#products-table td').mouseover(function(){
            $(this).addClass('active');
        })
        .mouseout(function(){
            $(this).removeClass('active');
        })
        .click(function(){
            var id = $(this).children('input').val();
            $('#b-wares')
            
            
        });
        
        //addbuttons
        $('.b-center-column .add-button').click(function(){
            $('#popup').remove();
            var popup = $("<div id='popup'>Error loading view. Please check \n\
                                your connection and try again.</div>");
            popup.load($.ProductListData.CreateProductUrl);
            popup.insertAfter(this);
            $('#popup').dialog({
                title: 'Add product',
                autoOpen:true,
                modal:true,
                height: 300,
                width: 500,
                buttons:{"Save": function()
                    {
                        var dialogObjext = $(this);
                        $('#create-product-form').ajaxSubmit(
                            function(resp){
                                if(resp!='success'){
                                    alert(resp);
                                }
                                else{
                                    dialogObjext.dialog("close");
                                    location.reload();
                                }
                            }
                        );         
                        
                    }
                }
            });
        });
        
		
		 
        //deletebuttons
        $('.b-center-column .delete-button').click(function(){
            $('#popup').remove();
            var popup = $("<div id='popup'>Error loading view. Please check \n\
                                your connection and try again.</div>");
            popup.load($.ProductListData.DeleteProductUrl);
            popup.insertAfter(this);
            $('#popup').dialog({
                title: 'Delete product',
                autoOpen:true,
                modal:true,
                height: 250,
                width: 440,
                buttons:{"Delete": function()
                    {
                        var dialogObjext = $(this);
                        $('#delete-product-form').ajaxSubmit(
                            function(resp){
                                if(resp!='success'){
                                    alert(resp);
                                }
                                else{
                                    dialogObjext.dialog("close");
                                    location.reload();
                                }
                            }
                        );         
                        
                    }
                }
            });
        });
		
        // editbuttons
        $('.b-center-column .edit-button').click(function(){
            $('#popup').remove();
            var popup = $("<div id='popup'>Error loading view. Please check \n\
                                your connection and try again.</div>");
            popup.load($.ProductListData.EditProductUrl);
            popup.insertAfter(this);
            $('#popup').dialog({
                title: 'Edit product',
                autoOpen:true,
                modal:true,
                height: 300,
                width: 500,
                buttons:{"Edit": function()
                    {
                        var dialogObjext = $(this);
                        $('#edit-product-form').ajaxSubmit(
                            function(resp){
                                if(resp!='success'){
                                    alert(resp);
                                }
                                else{
                                    dialogObjext.dialog("close");
                                    location.reload();
                                }
                            }
                        );         
                        
                    }
                }
            });
        });
    }        
}
